package cn.kone.controller;

import cn.kone.domain.Teacher;
import cn.kone.query.BaseQuery;
import cn.kone.service.ITeacherService;
import cn.kone.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {


    @Autowired
    private ITeacherService teacherService;

    /**
     * 查询全部教师信息
     *
     * @return
     */
    @GetMapping("/all")
    public R<List<Teacher>> findAllTeachers() {

        List<Teacher> teacherList = teacherService.findAllTeachers();
        return R.ok(teacherList);
    }

    /**
     * 根据id查询到教师信息
     *
     * @param id 教师id
     * @return
     */
    @GetMapping("/one/{id}")
    public R<Teacher> findOneTeacher(@PathVariable("id") Long id) {

        Teacher byIdTeacher = teacherService.findOneByIdTeacher(id);
        return R.ok(byIdTeacher);
    }


    /**
     * 新增教师信息
     *
     * @param teacher 教师信息
     * @return
     */
    @PostMapping
    public R<Void> addTeacher(@RequestBody Teacher teacher) {

        teacherService.addTeacher(teacher);
        return R.ok();

    }


    /**
     * 批量新增教师信息
     *
     * @param teacherList 教师信息的集合
     * @return
     */
    @PostMapping("/batch")
    public R<Void> batchAddTeacher(@RequestBody List<Teacher> teacherList) {

        teacherService.batchAddTeacher(teacherList);

        return R.ok();
    }


    /**
     * 修改教师信息
     *
     * @param teacher 教师信息
     * @return
     */
    @PutMapping
    public R<Void> updateTeacher(@RequestBody Teacher teacher) {

        teacherService.updateTeacher(teacher);
        return R.ok();
    }

    /**
     * 删除教师信息
     * @param id 教师id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public R<Void> deleteTeacher(@PathVariable("id") Long id){

        teacherService.deleteTeacher(id);
        return R.ok();
    }

    /**
     * 批量删除教师信息
     * @param ids 教师id的数组
     * @return
     */
    @DeleteMapping("/batch")
    public R<Void> batchDeleteTeacher(@PathVariable("id") Long[] ids){

        teacherService.batchdeleteTeacher(ids);
        return R.ok();
    }

    /**
     * 条件查询
     * @param baseQuery 根据查询条件
     * @return
     */
    @GetMapping("/baseQuery")
    public R<Teacher> findQueryTeacher(BaseQuery baseQuery){
        Teacher teacher = teacherService.findQueryTeacher(baseQuery);
        return R.ok(teacher);
    }

}
